import dateOptions from "@/utils/date"; //引入date的渲染
import goodsAdjust from "../../../api/GoodsAndGifts/goodsAdjust";

//引入axios的请求

let goodsAdjusts = {
    name: "index",
    data() {
        return {
            dateOptions,
            tableData: [],//数据信息
            searchParams: {
                currentPage: 1,//当前页
                pageSize: 5,//每页显示条数
                giftsName: '',

                startTime: '',//开始时间
                endTime: '',//结束时间
            },
            selectIds: [],//选中的数值
            options: [],//返回的信息数值
            batchIds: [],//批量删除  判断选中是否修改 和删除
            dialogVisible: false,//新增窗口默认不开
            formData: {},//新增表单信息
            total: 0,
            dialogVisible2: false,//新增审核跟踪窗口默认不开
            dialogVisible3: false,//新增审核跟踪窗口默认不开
            modelList: [],
            activeName: 'first'//添加列表默认勾选的框
        }
    },
    created() {//回调函数
        console.log("asd1")
        //查询
        this.searchPage();
    },
    methods: {
        /**
         * 查询所有
         */
        async searchPage() {
            let response = await goodsAdjust.searchPage(this.searchParams);
            console.log(goodsAdjust.searchPage(this.searchParams))
            console.log(response.data);
            this.total = response.total;//总行数复制
            this.tableData = response.data;//数据信息赋值
        },

        /**
         * 查询所有
         */
        async searchPage1() {
            let response = await goodsAdjust.searchPage1(this.searchParams);
            console.log(goodsAdjust.searchPage1(this.searchParams))
            console.log(response.data);
            this.total = response.total;//总行数复制
            this.tableData = response.data;//数据信息赋值
        },
        /**
         * 添加
         */
        async addOrEdit() {
            if (this.formData.id) {
                //修改
                await this.updateEntity();
            } else {
                //新增加
                await this.addEntity();
            }
            //刷新
            this.searchPage();
        },
        //修改
        async updateEntity() {
            await goodsAdjust.updateEntity(this.formData)

        },
        //新增
        async addEntity() {
            await goodsAdjust.addEntity(this.formData)
        },

        //根据id查询
        async findById() {
            this.formData = await goodsAdjust.findById(this.formData.id)
        },
        //根据id查询
        async findByAdjustId() {
            this.formData = await goodsAdjust.findByAdjustId(this.formData.id)
        },

        //时间框 选择时间
        chooseTime() {
            this.searchParams.startTime = this.dateOptions.startDate[0];
            this.searchParams.endTime = this.dateOptions.startDate[1];
        },

        //checkbox勾选改变
        selectChange1(val) {
            console.log(val)
            /**
             * 复选框选择修改 进行id赋值
             */
            if (val.length == 1) {
                //id赋值
                this.formData.id = val[0].id;
            } else {
                this.formData.id = "";
            }
            //勾选二个的时候修改失效  删除有效
            this.batchIds = val.map(item => item.id)
        },
        //新增审核记录
        async addGiftsEntity() {
            if (this.formData.approveStatus.equals("待审核")) {
                await goodsAdjust.addGiftsEntity(this.formData)
                this.searchPage()
            } else {
                this.searchPage()
            }
        },
        //根据id删除
        async deleteById() {
            await goodsAdjust.deleteById(this.formData.id)
            this.searchPage()
        },
        /**
         * 拿到品牌所有信息
         */
        async getAllBrand() {
            this.brandList = await goodsAdjust.getAllBrand();
        },
        /**
         * 拿到类型所有信息
         */
        async getAllType() {
            this.typeList = await goodsAdjust.getAllType();
        },
        /**
         * 拿到颜色所有信息
         */
        async getAllColor() {
            this.colorList = await goodsAdjust.getAllColor();
        },
        /**
         * 拿到类型所有信息
         */
        async getAllModel() {
            this.modelList = await goodsAdjust.getAllModel();
        },

        //checkbox勾选改变
        selectChange(val) {
            console.log(val)
            /**
             * 复选框选择修改 进行id赋值
             */
            if (val.length == 1) {
                //id赋值
                this.formData.id = val[0].id;
            } else {
                this.formData.id = "";
            }
            //勾选二个的时候修改失效  删除有效
            this.batchIds = val.map(item => item.id)
        },
        /**
         * 批量删除
         */
        async batchDeleteByIds() {
            await goodsAdjust.batchDelete(this.batchIds);
            console.log("批量删除触发")
            this.searchPage();
        },

        //点击下一页 发生改变
        currentPageChange(page) {
            this.searchParams.currentPage = page;//当前页赋值
            this.searchPage();//刷新页面
        },
        //点击重置
        resetForm() {
            //重置第一页信息
            this.searchParams = {currentPage: 1, pageSize: 5}
        },
        /**
         * 显示批量删除框
         */
        showBatchDeleteDialog() {
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.batchDeleteByIds();
            })
        },
    }
}

export default goodsAdjusts;